package com.bzframework.ai.springai.web;

import com.bzframework.core.auth.Authorization;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

/**
 * @Author bingzhong
 * @Date 2025/10/26
 */
@Tag(name = "spring ai")
@RestController
@RequestMapping("/spring-ai")
@RequiredArgsConstructor
@Authorization(ignore = true)// 忽略权限校验
public class SpringAiController {

    private final ChatModel dashScopeChatModel;

    @GetMapping("/version")
    @Operation(summary = "测试 spring ai 模块是否导入成功")
    public String helloSpringAi() {
        return "spring ai start succeed";
    }

    @GetMapping("/chat")
    @Operation(summary = "doChat")
    public String doChat(@RequestParam(required = false, defaultValue = "你是谁?") String message) {
        return dashScopeChatModel.call(message);
    }

    @GetMapping(value = "/stream-chat", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
    @Operation(summary = "doStreamChat")
    public Flux<String> doStreamChat(@RequestParam(required = false, defaultValue = "你是谁?") String message) {
        return dashScopeChatModel.stream(message);
    }

}
